using MicroMsg.Plugin.Sns.Scene;
using MicroMsg.Storage;
using MicroMsg.UI.Page;
using MicroMsg.UI.Util;
using Microsoft.Phone.Controls;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
namespace MicroMsg.UI.UserContrl
{
	public class AlbumSlideImage : SnsHttpImgCtrlBase
	{
		private const int LimitHeight = 768;
		private TloMedia tloMedia;
		private Image image;
		public string strUrl;
		private Stretch mStretch = 3;
		private bool bHasLimitedHeight;
		internal Canvas LayoutRoot;
		internal PerformanceProgressBar NetStatusProgressBar;
		private bool _contentLoaded;
		public AlbumSlideImage(bool bHasLimit = false)
		{
			this.InitializeComponent();
			if (bHasLimit)
			{
				this.bHasLimitedHeight = true;
				base.set_Height(768.0);
				base.set_Width(500.0);
				this.mStretch = 2;
			}
			else
			{
				base.set_Height(480.0);
				base.set_Width(500.0);
				this.mStretch = 3;
			}
			if (this.image == null)
			{
				this.image = new Image();
				this.LayoutRoot.get_Children().Add(this.image);
				this.image.set_HorizontalAlignment(1);
				this.image.set_VerticalAlignment(1);
				this.image.set_Height(base.get_Height());
				this.image.set_Width(base.get_Width());
				this.image.set_Stretch(this.mStretch);
				this.image.add_Tap(new EventHandler<GestureEventArgs>(this.img_Tap));
			}
		}
		protected override void ObjectCome(object object_0)
		{
			if (object_0 != null && object_0 is snsMediaDownloadInfo)
			{
				snsMediaDownloadInfo snsMediaDownloadInfo = object_0 as snsMediaDownloadInfo;
				if (snsMediaDownloadInfo.object_0 != null && snsMediaDownloadInfo.object_0 is BitmapImage)
				{
					this.HideLoadingTip();
					if (this.strUrl == snsMediaDownloadInfo.string_0)
					{
						this.image.set_Source(snsMediaDownloadInfo.object_0 as BitmapImage);
					}
				}
				return;
			}
		}
		private void img_Tap(object sender, GestureEventArgs e)
		{
			if (this.bHasLimitedHeight)
			{
				return;
			}
			Image element = sender as Image;
			BasePage rootPage = ToolFunction.GetRootPage();
			if (rootPage is AlbumSlideView)
			{
				AlbumSlideView albumSlideView = rootPage as AlbumSlideView;
				albumSlideView.get_ApplicationBar().set_IsVisible(false);
			}
			List<BitmapImage> list = new List<BitmapImage>();
			list.Add(this.image.get_Source() as BitmapImage);
			List<TloMedia> list2 = new List<TloMedia>();
			list2.Add(this.tloMedia);
			List<Rect> list3 = new List<Rect>();
			list3.Add(ToolFunction.GetElementPos(element));
			ScrollPicsCtrlArgs scrollPicsCtrlArgs = new ScrollPicsCtrlArgs(list2, list, 0, false);
			if (ScrollPicsCtrlArgs.CheckIsInfoOk(scrollPicsCtrlArgs))
			{
				ScrollPicListPage.GotoThisPage(scrollPicsCtrlArgs, null);
			}
		}
		public void LoadImage()
		{
			this.strUrl = this.tloMedia.strUrl;
			snsMediaDownloadInfo objReqInfo = new snsMediaDownloadInfo
			{
				string_0 = this.strUrl,
				urlType = (SnsUrlType)this.tloMedia.nUrlType,
				snsObjID = this.tloMedia.nID,
				priority = SnsPriority.HIGH
			};
			base.StartRequest(objReqInfo, true);
		}
		public void LoadTloMediaImage(TloMedia media)
		{
			if (this.tloMedia != media || this.image.get_Source() == null)
			{
				this.tloMedia = media;
				this.ShowLoadingTip();
				this.ClearImage();
				this.LoadImage();
			}
		}
		public void ClearImage()
		{
			BitmapImage bitmapImage = this.image.get_Source() as BitmapImage;
			if (bitmapImage == null)
			{
				return;
			}
			bitmapImage.set_UriSource(null);
			this.image.set_Source(null);
		}
		private void ShowLoadingTip()
		{
			this.NetStatusProgressBar.set_Visibility(0);
		}
		private void HideLoadingTip()
		{
			this.NetStatusProgressBar.set_Visibility(1);
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/Plugin/Sns/Album/UI/AlbumSlideImage.xaml", 2));
			this.LayoutRoot = (Canvas)base.FindName("LayoutRoot");
			this.NetStatusProgressBar = (PerformanceProgressBar)base.FindName("NetStatusProgressBar");
		}
	}
}
